<script setup>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import SplashLogo from './components/SplashLogo.vue';
import { getAppConfig } from './api/splash.api';

const router = useRouter();
const appConfig = ref({
    appName: '医预通',
    subtitle: '便捷的线上预约挂号平台',
    autoRedirectDelay: 3000
});

const loading = ref(true);

// 自动跳转逻辑
const autoRedirect = () => {
    setTimeout(() => {
        router.push('/login');
    }, appConfig.value.autoRedirectDelay);
};

// 立即体验按钮点击
const handleStart = () => {
    router.push('/login');
};

onMounted(async () => {
    try {
        // 获取应用配置
        const config = await getAppConfig();
        appConfig.value = config;
        loading.value = false;
    } catch (error) {
        console.error('获取应用配置失败:', error);
        loading.value = false;
    }

    // 自动跳转
    autoRedirect();
});
</script>

<template>
    <div class="splash-screen">
        <van-loading v-if="loading" color="#ffffff" />
        <template v-else>
            <div class="splash-content">
                <SplashLogo />
                <h1 class="title">{{ appConfig.appName }}</h1>
                <p class="subtitle">{{ appConfig.subtitle }}</p>
                <div class="button-container">
                    <van-button plain class="start-button" @click="handleStart" text-color="#ffffff" size="normal">
                        立即体验
                    </van-button>
                </div>
            </div>
        </template>
    </div>
</template>

<style scoped>
.splash-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background-color: #0080FF;
    color: white;
    text-align: center;
    padding: 0 20px;
}

.splash-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.title {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 12px;
    margin-top: 16px;
}

.subtitle {
    font-size: 14px;
    margin-bottom: 80px;
    opacity: 0.9;
}

.button-container {
    width: 100%;
    display: flex;
    justify-content: center;
}

.start-button {
    font-weight: bold;
    font-size: 16px;
    border: 1px solid white;
    border-radius: 4px;
    background-color: transparent;
    padding: 10px 40px;
    color: white;
}
</style>